VERSION 5.00
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "comdlg32.ocx"
Begin VB.Form MMIset 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Form1"
   ClientHeight    =   3510
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   6720
   ClipControls    =   0   'False
   Icon            =   "f3 MMIset.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   3510
   ScaleWidth      =   6720
   StartUpPosition =   3  'Windows Default
   Begin VB.OptionButton Typ 
      Caption         =   "SHELL"
      Height          =   255
      Index           =   3
      Left            =   1800
      TabIndex        =   35
      Top             =   1260
      Width           =   855
   End
   Begin VB.CommandButton Command1 
      Caption         =   "-"
      Height          =   255
      Index           =   3
      Left            =   6180
      TabIndex        =   34
      Top             =   2340
      Width           =   255
   End
   Begin VB.CommandButton Command1 
      Caption         =   "+"
      Height          =   255
      Index           =   2
      Left            =   5940
      TabIndex        =   33
      Top             =   2340
      Width           =   255
   End
   Begin VB.CommandButton Command1 
      Caption         =   "-"
      Height          =   255
      Index           =   1
      Left            =   5580
      TabIndex        =   32
      Top             =   2340
      Width           =   255
   End
   Begin VB.CommandButton Command1 
      Caption         =   "+"
      Height          =   255
      Index           =   0
      Left            =   5340
      TabIndex        =   31
      Top             =   2340
      Width           =   255
   End
   Begin VB.TextBox NewVal 
      Height          =   285
      Index           =   11
      Left            =   5940
      TabIndex        =   17
      Text            =   "Text1"
      Top             =   1980
      Width           =   495
   End
   Begin VB.TextBox NewVal 
      Height          =   285
      Index           =   10
      Left            =   5340
      TabIndex        =   16
      Text            =   "Text1"
      Top             =   1980
      Width           =   495
   End
   Begin VB.TextBox NewVal 
      Height          =   285
      Index           =   9
      Left            =   3360
      TabIndex        =   6
      Text            =   "Text1"
      Top             =   960
      Width           =   3255
   End
   Begin VB.CheckBox Opt 
      Caption         =   "Enable Write."
      Height          =   255
      Index           =   2
      Left            =   1800
      TabIndex        =   5
      Top             =   960
      Width           =   1455
   End
   Begin MSComDlg.CommonDialog Selector 
      Left            =   6240
      Top             =   0
      _ExtentX        =   847
      _ExtentY        =   847
      _Version        =   393216
   End
   Begin VB.CheckBox Opt 
      Caption         =   "Use color."
      Height          =   255
      Index           =   1
      Left            =   3420
      TabIndex        =   11
      Top             =   2280
      Width           =   1095
   End
   Begin VB.TextBox NewVal 
      Height          =   285
      Index           =   8
      Left            =   2640
      TabIndex        =   15
      Text            =   "Text1"
      Top             =   2880
      Width           =   615
   End
   Begin VB.TextBox NewVal 
      Height          =   285
      Index           =   7
      Left            =   1920
      TabIndex        =   14
      Text            =   "Text1"
      Top             =   2880
      Width           =   495
   End
   Begin VB.TextBox NewVal 
      Height          =   285
      Index           =   6
      Left            =   1200
      TabIndex        =   13
      Text            =   "Text1"
      Top             =   2880
      Width           =   495
   End
   Begin VB.TextBox NewVal 
      Height          =   285
      Index           =   5
      Left            =   2280
      TabIndex        =   10
      Text            =   "Text1"
      Top             =   2280
      Width           =   975
   End
   Begin VB.TextBox NewVal 
      Height          =   285
      Index           =   4
      Left            =   1200
      TabIndex        =   9
      Text            =   "Text1"
      Top             =   2280
      Width           =   975
   End
   Begin VB.CheckBox Opt 
      Caption         =   "Show Desc Text."
      Height          =   255
      Index           =   0
      Left            =   120
      TabIndex        =   4
      Top             =   960
      Width           =   1575
   End
   Begin VB.OptionButton Typ 
      Caption         =   "Analog"
      Height          =   255
      Index           =   2
      Left            =   120
      TabIndex        =   12
      Top             =   2880
      Width           =   855
   End
   Begin VB.TextBox NewVal 
      Height          =   285
      Index           =   3
      Left            =   120
      TabIndex        =   3
      Text            =   "Text1"
      Top             =   600
      Width           =   6495
   End
   Begin VB.OptionButton Typ 
      Caption         =   "RAW"
      Height          =   255
      Index           =   0
      Left            =   120
      TabIndex        =   7
      Top             =   1740
      Width           =   855
   End
   Begin VB.CommandButton pB 
      Caption         =   "Accept"
      Default         =   -1  'True
      Height          =   375
      Index           =   1
      Left            =   4740
      TabIndex        =   18
      TabStop         =   0   'False
      Top             =   3000
      Width           =   855
   End
   Begin VB.CommandButton pB 
      Cancel          =   -1  'True
      Caption         =   "Cancel"
      Height          =   375
      Index           =   0
      Left            =   5640
      TabIndex        =   19
      TabStop         =   0   'False
      Top             =   3000
      Width           =   855
   End
   Begin VB.TextBox NewVal 
      Height          =   285
      Index           =   2
      Left            =   3360
      TabIndex        =   2
      Text            =   "Text1"
      Top             =   240
      Width           =   3255
   End
   Begin VB.TextBox NewVal 
      Height          =   285
      Index           =   1
      Left            =   1800
      TabIndex        =   1
      Text            =   "Text1"
      Top             =   240
      Width           =   1455
   End
   Begin VB.TextBox NewVal 
      Height          =   285
      Index           =   0
      Left            =   120
      TabIndex        =   0
      Text            =   "Text1"
      Top             =   240
      Width           =   1575
   End
   Begin VB.OptionButton Typ 
      Caption         =   "Digital"
      Height          =   255
      Index           =   1
      Left            =   120
      TabIndex        =   8
      Top             =   2280
      Width           =   855
   End
   Begin VB.Label Label 
      AutoSize        =   -1  'True
      Caption         =   "Shell command"
      Height          =   195
      Index           =   11
      Left            =   3360
      TabIndex        =   36
      Top             =   1320
      Width           =   1080
   End
   Begin VB.Label Label 
      AutoSize        =   -1  'True
      Caption         =   "Display obj width"
      Height          =   195
      Index           =   10
      Left            =   4620
      TabIndex        =   30
      Top             =   1740
      Width           =   1185
   End
   Begin VB.Label Label 
      AutoSize        =   -1  'True
      Caption         =   "Height"
      Height          =   195
      Index           =   9
      Left            =   5940
      TabIndex        =   29
      Top             =   1740
      Width           =   465
   End
   Begin VB.Line Line1 
      X1              =   120
      X2              =   6600
      Y1              =   1560
      Y2              =   1560
   End
   Begin VB.Label Label 
      AutoSize        =   -1  'True
      Caption         =   "Write to ddeItem"
      Height          =   195
      Index           =   8
      Left            =   5400
      TabIndex        =   28
      Top             =   1320
      Width           =   1170
   End
   Begin VB.Label Label 
      AutoSize        =   -1  'True
      Caption         =   "Dec. points"
      Height          =   195
      Index           =   7
      Left            =   2640
      TabIndex        =   27
      Top             =   2640
      Width           =   810
   End
   Begin VB.Label Label 
      AutoSize        =   -1  'True
      Caption         =   "Offset"
      Height          =   195
      Index           =   6
      Left            =   1920
      TabIndex        =   26
      Top             =   2640
      Width           =   420
   End
   Begin VB.Label Label 
      AutoSize        =   -1  'True
      Caption         =   "Scale"
      Height          =   195
      Index           =   5
      Left            =   1200
      TabIndex        =   25
      Top             =   2640
      Width           =   405
   End
   Begin VB.Label Label 
      AutoSize        =   -1  'True
      Caption         =   "Off Desc"
      Height          =   195
      Index           =   4
      Left            =   2280
      TabIndex        =   24
      Top             =   2040
      Width           =   630
   End
   Begin VB.Label Label 
      AutoSize        =   -1  'True
      Caption         =   "On Desc"
      Height          =   195
      Index           =   3
      Left            =   1200
      TabIndex        =   23
      Top             =   2040
      Width           =   630
   End
   Begin VB.Label Label 
      AutoSize        =   -1  'True
      Caption         =   "ddItem"
      Height          =   195
      Index           =   2
      Left            =   3360
      TabIndex        =   22
      Top             =   0
      Width           =   480
   End
   Begin VB.Label Label 
      AutoSize        =   -1  'True
      Caption         =   "ddeTopic"
      Height          =   195
      Index           =   1
      Left            =   1800
      TabIndex        =   21
      Top             =   0
      Width           =   675
   End
   Begin VB.Label Label 
      AutoSize        =   -1  'True
      Caption         =   "ddeApp"
      Height          =   195
      Index           =   0
      Left            =   120
      TabIndex        =   20
      Top             =   0
      Width           =   555
   End
End
Attribute VB_Name = "MMIset"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
DefInt A-Z

Private Sub Command1_Click(Index As Integer)
    Select Case Index
        Case 0 'Width More
            NewVal(10).Text = (NewVal(10).Text \ LAY.SnapX) * LAY.SnapX + LAY.SnapX
        Case 1 'Width Less
            NewVal(10).Text = (NewVal(10).Text \ LAY.SnapX) * LAY.SnapX - LAY.SnapX
        Case 2 'Height More
            NewVal(11).Text = (NewVal(11).Text \ LAY.SnapY) * LAY.SnapY + LAY.SnapY
        Case 3 'Height Less
            NewVal(11).Text = (NewVal(11).Text \ LAY.SnapY) * LAY.SnapY - LAY.SnapY
    End Select
    If NewVal(10) < LAY.SnapX Then NewVal(10) = LAY.SnapX
    If NewVal(10) > LAY.SnapX * 10 Then NewVal(10) = LAY.SnapX * 10
    If NewVal(11) < LAY.SnapY Then NewVal(11) = LAY.SnapY
    If NewVal(11) > LAY.SnapY * 10 Then NewVal(11) = LAY.SnapY * 10
End Sub

Private Sub Form_Load()

    Me.Caption = LAY.Title & " - (VDT) Object Settings."
    Me.Left = LAY.SETLeft
    Me.Top = LAY.SETTop
    pB(1).Enabled = False
        
    'Get a pointer to the object
    Dim pT: pT = Vdt.Index
    
    'Get Link info
    NewVal(0) = getDDEAppName(Vdt.Link(pT).LinkTopic)
    NewVal(1) = getDDETopicName(Vdt.Link(pT).LinkTopic)
    NewVal(2) = Vdt.Link(pT).LinkItem
    'Get Desc
    NewVal(3) = Vdt.Desc(pT)
    If Vdt.Desc(pT).Visible = True Then Opt(0) = 1 Else Opt(0) = 0
    'Get Writable
    If Vdt.Item(pT).Writable = True Then Opt(2) = 1 Else Opt(2) = 0
    If Opt(2) = 1 Then
        If Vdt.Item(pT).Type <> 3 Then
         Label(8).Visible = True
         Label(11).Visible = False
        Else
         Label(8).Visible = False
         Label(11).Visible = True
        End If
        NewVal(9).Visible = True
        NewVal(9).Text = Vdt.Item(pT).LinkWriteItem
    Else
        Label(8).Visible = False
        NewVal(9).Visible = False
        NewVal(9).Text = ""
    End If
    'Get Type
    Select Case Vdt.Item(pT).Type
        Case 0: Typ(0).Value = True
        Case 1: Typ(1).Value = True
        Case 2: Typ(2).Value = True
        Case 3: Typ(3).Value = True
    End Select
    'Get On/Off State Text
    NewVal(4) = Vdt.Item(pT).OnState
    NewVal(5) = Vdt.Item(pT).OffState
    'Get Color for On/Off
    Opt(1) = Vdt.Item(pT).DUseColor
    If Opt(1) = 1 Then
        NewVal(4).BackColor = Vdt.Item(pT).DOnColor
        NewVal(5).BackColor = Vdt.Item(pT).DOffColor
    End If
    'Get Scaling
    NewVal(6) = Vdt.Item(pT).Scl
    NewVal(7) = Vdt.Item(pT).Offset
    NewVal(8) = Vdt.Item(pT).Round
    
    'Get Display Width and Height
    NewVal(10) = Vdt.Disp(pT).Width
    NewVal(11) = Vdt.Disp(pT).Height
    
End Sub

Private Sub upDateSettings()
    
   Dim pT: pT = Vdt.Index
    
   'Get the current Link() mode
   Dim AsFndLinkMode As Integer
   AsFndLinkMode = Vdt.Link(pT).LinkMode
   
   'Update link address
   Vdt.Link(pT).LinkMode = vbLinkNone
   If Not Typ(3) Then
      Vdt.Link(pT).LinkTopic = Trim(NewVal(0)) & "|" & Trim(NewVal(1))
   Else
      Vdt.Link(pT).LinkTopic = ""
   End If
   Vdt.Link(pT).LinkItem = Trim(NewVal(2))
   Vdt.Item(pT).LinkWriteItem = Trim(NewVal(9).Text)
   
   'Restart the link if required
   If NewVal(0) <> "" And NewVal(1) <> "" And NewVal(2) <> "" And AsFndLinkMode = vbLinkAutomatic And Vdt.LinkRun Then
      On Error Resume Next
      Vdt.Link(pT).LinkMode = vbLinkAutomatic
      DoEvents
      On Error GoTo 0
   End If
   
      
      'Update the LinkType
      If Typ(0) Then Vdt.Item(pT).Type = 0
      If Typ(1) Then Vdt.Item(pT).Type = 1
      If Typ(2) Then Vdt.Item(pT).Type = 2
      If Typ(3) Then Vdt.Item(pT).Type = 3
      
      Vdt.Item(pT).OnState = NewVal(4)
      Vdt.Item(pT).OffState = NewVal(5)
      Vdt.Item(pT).Scl = NewVal(6)
      Vdt.Item(pT).Offset = NewVal(7)
      Vdt.Item(pT).Round = NewVal(8)
      Vdt.Item(pT).DUseColor = Opt(1)
      Vdt.Item(pT).DOnColor = NewVal(4).BackColor
      Vdt.Item(pT).DOffColor = NewVal(5).BackColor
      
      'Uodate Disp Obj
      'Resize
      Vdt.Disp(pT).Width = NewVal(10)
      Vdt.Disp(pT).Height = NewVal(11)
      
      'Writable
      If Opt(2) = 1 Then
         Vdt.Item(pT).Writable = True
         Vdt.Disp(pT).Font.Bold = True
      Else
         Vdt.Item(pT).Writable = False
         Vdt.Disp(pT).Font.Bold = False
         Vdt.Disp(pT).BackColor = vbWhite
      End If
      
      'Back color if required - Typ 1 Digital
      If Vdt.Item(pT).Type <> 1 Then Vdt.Disp(pT).BackColor = vbWhite
      
      'Alignment
      Select Case Vdt.Item(pT).Type
         Case 0: Vdt.Disp(pT).Alignment = VDTCtrl.ALIGN_0
         Case 1: Vdt.Disp(pT).Alignment = VDTCtrl.ALIGN_1
         Case 2: Vdt.Disp(pT).Alignment = VDTCtrl.ALIGN_2
         Case 3: Vdt.Disp(pT).Alignment = VDTCtrl.ALIGN_3
      End Select
      
      'Update Desc object
      Vdt.Desc(pT) = Trim(NewVal(3))
      If Vdt.Desc(pT).Caption = "" Or Opt(0) = 0 Then
         Vdt.Desc(pT).Visible = False
      Else
         Vdt.Desc(pT).Visible = True
      End If
      
      'Update tool tip
      VDTCtrl.VdtUpDateToolTip pT

End Sub

Private Sub Form_Unload(Cancel As Integer)
    LAY.SETLeft = Me.Left
    LAY.SETTop = Me.Top
End Sub

Private Sub LinkType_Click(Index As Integer)
    pB(1).Enabled = True
End Sub

Private Sub NewVal_Change(Index As Integer)
    pB(1).Enabled = True
End Sub

Private Sub NewVal_DblClick(Index As Integer)
    If Opt(1) = 1 And (Index = 4 Or Index = 5) Then
        Selector.Color = NewVal(Index).BackColor
        Selector.ShowColor
        NewVal(Index).BackColor = Selector.Color
    End If
End Sub

Private Sub NewVal_GotFocus(Index As Integer)
    NewVal(Index).SelStart = 0
    NewVal(Index).SelLength = Len(NewVal(Index))
End Sub

Private Sub opt_Click(Index As Integer)
    'Enable Accept PB
    pB(1).Enabled = True
    Select Case Index
        Case 0 'Show Desc
        Case 1 'Colored Digitals
            If Opt(1) = 0 Then
            NewVal(4).BackColor = vbWhite
            NewVal(5).BackColor = vbWhite
        Else
            NewVal(4).BackColor = vbGreen
            NewVal(5).BackColor = vbRed
        End If
        Case 2 'Writable
            If Opt(2) = 1 Then
                Label(8).Visible = True
                NewVal(9).Visible = True
                NewVal(9).Text = NewVal(2).Text
            Else
                Label(8).Visible = False
                NewVal(9).Visible = False
                NewVal(9).Text = ""
            End If
    End Select
End Sub

Private Sub pB_Click(Index As Integer)
    Select Case Index
        Case 0
            Unload Me
        Case 1
            upDateSettings
            Unload Me
    End Select
End Sub

Private Function getDDEAppName(LblTopic As String) As String
    If LblTopic <> "" And InStr(LblTopic, "|") > 0 Then
        getDDEAppName = Trim(Left(LblTopic, InStr(LblTopic, "|") - 1))
    Else
        getDDEAppName = ""
    End If
End Function

Private Function getDDETopicName(LblTopic As String) As String
    If LblTopic <> "" And InStr(LblTopic, "|") > 0 Then
        getDDETopicName = Trim(Mid(LblTopic, InStr(LblTopic, "|") + 1))
    Else
        getDDETopicName = ""
    End If
End Function

Private Sub Typ_Click(Index As Integer)
    pB(1).Enabled = True
   
   'Check for New LMMI option Typ(3) and configure form to suit.
   Select Case Index
      Case 3
         If Typ(Index).Value = True Then
            NewVal(0) = ""
            NewVal(1) = ""
            NewVal(2) = ""
            Opt(2).Value = 1
            Label(8).Visible = False
            Label(11).Visible = True
         Else
            Opt(2).Value = 0
            Label(8).Visible = False
            Label(11).Visible = False
            NewVal(9) = ""
         End If
   End Select
End Sub
